package edu.nf.takeoutdemo.web.admin;

import edu.nf.takeoutdemo.commons.base.BaseController;
import edu.nf.takeoutdemo.commons.result.PageResult;
import edu.nf.takeoutdemo.commons.result.Result;
import edu.nf.takeoutdemo.model.dto.DishDTO;
import edu.nf.takeoutdemo.model.dto.SetmealDTO;
import edu.nf.takeoutdemo.model.dto.SetmealPageQueryDTO;
import edu.nf.takeoutdemo.model.entity.Setmeal;
import edu.nf.takeoutdemo.model.vo.SetmealVO;
import edu.nf.takeoutdemo.service.SetmealService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author zjl
 * @date 2025/10/28
 */
@RestController("adminSetmealController")
@Slf4j
@RequestMapping("/admin/setmeal")
@RequiredArgsConstructor
public class SetmealController extends BaseController {

    private final SetmealService setmealService;

    @PostMapping
    public Result<?> save(@RequestBody SetmealDTO setmealDTO) {
        setmealService.saveWithDish(setmealDTO);
        return success();
    }

    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult pageResult =  setmealService.pageQuery(setmealPageQueryDTO);
        return success(pageResult);
    }

    @DeleteMapping
    public Result<?> delete(@RequestParam List<Long> ids) {
        setmealService.deleteBatch(ids);
        return success();
    }

    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable("id") Long id) {
        SetmealVO setmealVO = setmealService.getByIdWithDish(id);
        return success(setmealVO);
    }

    @PutMapping
    public Result<?> update(@RequestBody SetmealDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return success();
    }

    @PostMapping("/status/{status}")
    public Result<?> startOrStop(@PathVariable("status") Integer status, Long id) {
        setmealService.startOrStop(status, id);
        return success();
    }
}
